﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;


namespace WebApplication1
{
    public partial class Register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            var name = TextBox1.Text.Trim();
            var pwd = TextBox2.Text.Trim();
            var pwd2 = TextBox3.Text.Trim();
            var uid = !string.IsNullOrEmpty(name);
            var password = !string.IsNullOrEmpty(pwd);
            var repwd = (pwd == pwd2);
            if (pwd==pwd2)
            {
                var sql = string.Format("select * from Users where UserName='{0}'", name);
                var dt = DbHelper.GetData(sql);
              //  SqlDataReader dataReader = dt.ExecuteReader();
              //  if (!dataReader.Read())
                if(dt.Rows.Count==0)
                {
                    //dataReader.Close();
                    if (uid && password && repwd)
                    {
                        var sqlStr = string.Format("insert into Users(UserName,UserPassword)values('{0}','{1}')", name, pwd);
                        DbHelper.AddOrUpdateOrDelete(sqlStr);
                        Response.Write("注册成功");
                    }
                    else
                    {
                        Response.Write("不能为空置");
                    }
                }
                else
                {

                    Response.Write("用户名已存在");
                }
            }
            else
            {
                Response.Write("请核对密码");
            }

          
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Response.Redirect("Login.aspx");
        }
    }
}